package com.dtruth.dataflow.dbmanager;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * redis manager
 * 
 * @author yhl@feheadline.com
 * @date 2014年10月22日
 */
public class RedisManager {

	private Jedis jedis;// 非切片额客户端连接
	private JedisPool jedisPool;// 非切片连接池

	public RedisManager(String host, int port, int insNum) {
		initialPool(host, port);
		jedis = jedisPool.getResource();
		jedis.select(insNum);
	}

	/**
	 * 初始化非切片池
	 */
	private void initialPool(String host, int port) {
		// 池基本配置
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(5);
		config.setMaxIdle(3);
		config.setMaxWaitMillis(20001);
		config.setTestOnBorrow(false);
		jedisPool = new JedisPool(config, host, port);
	}

	public Jedis getJedis() {
		return this.jedis;
	}
}
